/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javamu;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 
 * @author Administrator
 */
public class JavaMUUnit {

	/**
	 * @param args the command line arguments
	 */
	public static void main(String[] args) {
		Calendar cal = Calendar.getInstance();
		int year = cal.get(Calendar.YEAR);
		int month = cal.get(Calendar.MONTH) + 1; //这处比较奇特，0代表1月，11代表12月
		int day = cal.get(Calendar.DAY_OF_MONTH);
		System.out.println("今天是" + year + "-" + String.valueOf(month) + "-" + String.valueOf(day));
		Date dtd = cal.getTime(); //转化成Date对象
		System.out.println(dtd.toString());
		long dst = cal.getTimeInMillis(); //转化成时间戳
		System.out.println(dst);
		
		Double db = 1234.5;
		String st = db.toString() + "1234";
		System.out.println(st);
		
		//时间及日期
		Date dt = new Date(); //java.util.Date;
		System.out.println(dt);
		
		//时间格式化
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dt_str = sdf.format(dt);
		System.out.println(dt_str);
		
		//字符串转时间
		try {
			String dt_str2 = "2016-11-12 12:13:14";
			Date dt2 = sdf.parse(dt_str2); //以sdf方式来转化时间
			System.out.println(dt2);
		} catch (Exception e) {
			System.err.println("时间字符串转时间失败");
			System.err.println(e);
		}
	}
}
